//
//  MineTopBottomItem.m
//  BaseProject
//
//  Created by 王盼盼 on 2024/10/30.
//  Copyright © 2024 wangpanpan. All rights reserved.
//

#import "MineTopBottomItem.h"

@interface MineTopBottomItem ()
@property(nonatomic, strong) UIImageView *imageView;
@property(nonatomic, strong) UILabel *titleLabel;
@property(nonatomic, strong) UILabel *subTitleLabel;
@end

@implementation MineTopBottomItem
- (void)makeUI {
    self.backgroundColor = UIColor.clearColor;
}
- (void)setData:(MineItemModel *)data {
    _data = data;
    if (data.layout == ItemLayoutTB) {
        if (data.style == ItemStyleOrder) {
            [self addSubview:self.imageView];
            [self addSubview:self.titleLabel];
            
            [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.size.mas_equalTo(data.picSize);
                make.top.mas_equalTo(0);
                make.centerX.mas_equalTo(0);
            }];
            [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(self.imageView.mas_bottom).mas_offset(data.itemMargin);
                make.centerX.mas_equalTo(0);
            }];
            
            self.imageView.image = [UIImage imageNamed:data.picUrl];
            self.titleLabel.text = data.title;
            self.titleLabel.font = data.titleFont;
            self.titleLabel.textColor = data.titleColor;
        } else if (data.style == ItemStyleCollect) {
            [self addSubview:self.titleLabel];
            [self addSubview:self.subTitleLabel];
            
            [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(0);
                make.centerX.mas_equalTo(0);
            }];
            [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(data.itemMargin);
                make.centerX.mas_equalTo(0);
            }];
            
            self.titleLabel.text = data.title;
            self.titleLabel.font = data.titleFont;
            self.titleLabel.textColor = data.titleColor;
            
            self.subTitleLabel.text = data.subTitle;
            self.subTitleLabel.font = data.subTitleFont;
            self.subTitleLabel.textColor = data.subtTitleColor;
        } else if (data.style == ItemStyleCredit) {
            [self addSubview:self.titleLabel];
            [self addSubview:self.subTitleLabel];
            
            [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(0);
                make.left.mas_equalTo(0);
                make.height.mas_equalTo(21);
            }];
            [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(data.itemMargin);
                make.left.mas_equalTo(0);
                make.height.mas_equalTo(21);
            }];
            
            self.titleLabel.text = data.title;
            self.titleLabel.font = data.titleFont;
            self.titleLabel.textColor = data.titleColor;
            
            self.subTitleLabel.text = data.subTitle;
            self.subTitleLabel.font = data.subTitleFont;
            self.subTitleLabel.textColor = data.subtTitleColor;
            
            if (data.hasTips) {
                [self addSubview:self.imageView];
                [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(self.titleLabel.mas_right).mas_equalTo(4);
                    make.size.mas_equalTo(CGSizeMake(16, 16));
                    make.centerY.mas_equalTo(self.titleLabel);
                }];
                self.imageView.image = [UIImage imageNamed:ImageName.icon_shuoming];
                UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickImageView:)];
                self.imageView.userInteractionEnabled = YES;
                [self.imageView addGestureRecognizer:tap];
            }
        }
    } else if (data.layout == ItemLayoutStack) {
        [self addSubview:self.imageView];
        [self.imageView addSubview:self.titleLabel];
        [self.imageView addSubview:self.subTitleLabel];
        
        [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(0);
        }];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.mas_equalTo(16);
        }];
        [self.subTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.titleLabel.mas_bottom).mas_offset(data.itemMargin);
            make.left.mas_equalTo(16);
        }];
        self.imageView.image = [UIImage imageNamed:data.picUrl];
        
        self.titleLabel.text = data.title;
        self.titleLabel.font = data.titleFont;
        self.titleLabel.textColor = data.titleColor;
        
        self.subTitleLabel.text = data.subTitle;
        self.subTitleLabel.font = data.subTitleFont;
        self.subTitleLabel.textColor = data.subtTitleColor;
    }
}
- (void)clickImageView:sender {
    !self.clickImageViewCallBackImageViewFrame ?: self.clickImageViewCallBackImageViewFrame(self, self.imageView.frame);
}
#pragma mark - lazy
- (UIImageView *)imageView {
    if (!_imageView) {
        UIImageView *iv = [[UIImageView alloc]init];
        iv.contentMode = UIViewContentModeScaleAspectFill;
        iv.clipsToBounds = YES;
        _imageView = iv;
    }
    return _imageView;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        UILabel *lab = [[UILabel alloc]init];
        lab.textAlignment = NSTextAlignmentCenter;
        lab.numberOfLines = 1;
        _titleLabel = lab;
    }
    return _titleLabel;
}
- (UILabel *)subTitleLabel {
    if (!_subTitleLabel) {
        UILabel *lab = [[UILabel alloc]init];
        lab.textAlignment = NSTextAlignmentCenter;
        lab.numberOfLines = 1;
        _subTitleLabel = lab;
    }
    return _subTitleLabel;
}
@end
